package org.xyl.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;

/**
 * MCP服务器安全配置
 */
@Configuration
@EnableWebSecurity
public class SecurityConfig {
    
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http
            .csrf(csrf -> csrf.disable()) // 在生产环境中应该启用CSRF保护
            .authorizeHttpRequests(authorize -> authorize
                .requestMatchers("/api/mcp/**").authenticated() // 所有MCP API需要认证
                .anyRequest().permitAll()
            )
            .httpBasic(Customizer.withDefaults()); // 使用基本认证，生产环境中建议使用OAuth2.0
        
        return http.build();
    }
}
